home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 401-425 / disk_405 / gifmachine / sources / rgbdiff.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  876b  |  37 lines

  1. /* Note:  this colour comparison routine was snitched from HamSharp.
  2.  
  3.    This has the side effect of allowing one to compare colour errors gotten
  4.    with GIFMachine to those gotten with (S)HamSharp.
  5. */
  6.  
  7. #include "GIFMachine.h"
  8.  
  9. static UBYTE Diff[16][16];
  10. static UBYTE Intensity[16][16][16];
  11.  
  12. extern struct Library *MathIeeeDoubBasBase;
  13.  
  14. void InitDiff(void)
  15. {
  16.     register int i;
  17.     register int j;
  18.     register int r;
  19.     register int g;
  20.     register int b;
  21.  
  22.     for (i = 0; i < 16; i++)
  23.         for (j = 0; j < 16; j++)
  24.             Diff[i][j] = (i - j) * (i - j);
  25.  
  26.     for (r = 0; r < 16; r++)
  27.         for (g = 0; g < 16; g++)
  28.             for (b = 0; b < 16; b++)
  29.                 Intensity[r][g][b] = (int)(.299 * r + .587 * g + .114 * b);
  30. }
  31.  
  32. ULONG RGBdiff(UBYTE r1, UBYTE g1, UBYTE b1, UBYTE r2, UBYTE g2, UBYTE b2)
  33. {
  34.     return (ULONG)(Diff[Intensity[r1][g1][b1]][Intensity[r2][g2][b2]] +
  35.         Diff[r1][r2] + Diff[g1][g2] + Diff[b1][b2]);
  36. }
  37.